package com.ruoyi.information.service.pc.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.information.mapper.pc.CloudClassroomMapper;
import com.ruoyi.information.domain.pc.CloudClassroom;
import com.ruoyi.information.service.pc.ICloudClassroomService;

/**
 * 云课堂列表Service业务层处理
 *
 * @author ruoyi
 * @date 2023-05-17
 */
@Service
public class CloudClassroomServiceImpl implements ICloudClassroomService
{
    @Autowired
    private CloudClassroomMapper cloudClassroomMapper;

    /**
     * 查询云课堂列表
     *
     * @param id 云课堂列表主键
     * @return 云课堂列表
     */
    @Override
    public CloudClassroom selectCloudClassroomById(Long id)
    {
        /*增加点击量和浏览量*/
        cloudClassroomMapper.updateNum(id);
        CloudClassroom cloudClassroom = cloudClassroomMapper.selectCloudClassroomById(id);
        if (cloudClassroom!=null&& SecurityUtils.getUserId() != 0){
            /*是否收藏*/
            cloudClassroom.setIsLike(cloudClassroomMapper.selectClassroomByCollection(id, SecurityUtils.getUserId()));
        }
        return cloudClassroom;
    }

    /**
     * 查询云课堂列表列表
     *
     * @param cloudClassroom 云课堂列表
     * @return 云课堂列表
     */
    @Override
    public List<CloudClassroom> selectCloudClassroomList(CloudClassroom cloudClassroom)
    {
        return cloudClassroomMapper.selectCloudClassroomList(cloudClassroom);
    }

    /**
     * 新增云课堂列表
     *
     * @param cloudClassroom 云课堂列表
     * @return 结果
     */
    @Override
    public int insertCloudClassroom(CloudClassroom cloudClassroom)
    {
        cloudClassroom.setCreateTime(DateUtils.getNowDate());
        return cloudClassroomMapper.insertCloudClassroom(cloudClassroom);
    }

    /**
     * 修改云课堂列表
     *
     * @param cloudClassroom 云课堂列表
     * @return 结果
     */
    @Override
    public int updateCloudClassroom(CloudClassroom cloudClassroom)
    {
        cloudClassroom.setUpdateTime(DateUtils.getNowDate());
        return cloudClassroomMapper.updateCloudClassroom(cloudClassroom);
    }

    /**
     * 批量删除云课堂列表
     *
     * @param ids 需要删除的云课堂列表主键
     * @return 结果
     */
    @Override
    public int deleteCloudClassroomByIds(Long[] ids)
    {
        return cloudClassroomMapper.deleteCloudClassroomByIds(ids);
    }

    /**
     * 删除云课堂列表信息
     *
     * @param id 云课堂列表主键
     * @return 结果
     */
    @Override
    public int deleteCloudClassroomById(Long id)
    {
        return cloudClassroomMapper.deleteCloudClassroomById(id);
    }
}
